import { system } from "@minecraft/server";

export const events = {
  onTick({ block }) {
    const directions = [
      { x: 1, y: 0, z: 0 },
      { x: -1, y: 0, z: 0 },
      { x: 0, y: 0, z: 1 },
      { x: 0, y: 0, z: -1 },
      { x: 0, y: 1, z: 0 }
    ];

    for (const dir of directions) {
      const neighbor = block.dimension.getBlock(BlockLocation.create(
        block.location.x + dir.x,
        block.location.y + dir.y,
        block.location.z + dir.z
      ));

      if (neighbor?.typeId === "minecraft:water") {
        const loc = block.location;
        const dim = block.dimension
        system.runTimeout(() => {
          dim.setBlock(loc, "minecraft:air");
          dim.playSound("break.calcite", loc);
        }, 100);
        break;
      }
    }
  }
};